<?php

  // Ensure a valid runtime environment or die
  if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

  // -- webMS Modification --
  // Check if osCommerce environment is already loaded
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      // Reconnect to osCommerce Database
      tep_db_connect() or die('Unable to connect to database server!');
    }
    // Load osCommerce Globals for Boxes
    global $category_links, $languages_id, $catID, $catID_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    // Load osCommerce Environment for the First Time
    require('components/'.$option.'/includes/application_top.php');
  }

  if (!tep_session_is_registered('affiliate_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_AFFILIATE, '', 'SSL'));
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_AFFILIATE_BANNERS_TEXT);

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_AFFILIATE_BANNERS_TEXT));

  $affiliate_banners_values = tep_db_query("select * from " . TABLE_AFFILIATE_BANNERS . " order by affiliate_banners_title");
?>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>
    <td></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="contentheading"><?php echo HEADING_TITLE; ?></td>
            <td align="right"><?php echo tep_image(DIR_WS_IMAGES . 'affiliate_links.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
	  <tr>
            <td colspan=2 class="main"><?php echo TEXT_INFORMATION; ?></td>
          </tr>
        </table>
	</td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><table width="100%" align="center" border="0" cellpadding="0" cellspacing="0"><td>
<?php 
if (tep_db_num_rows($affiliate_banners_values)) { 

   while ($affiliate_banners = tep_db_fetch_array($affiliate_banners_values)) { 
$prod_id=$affiliate_banners['affiliate_products_id']; 
$prod_name=$affiliate_banners['affiliate_banners_title']; 
$ban_id=$affiliate_banners['affiliate_banners_id']; 
    switch (AFFILIATE_KIND_OF_BANNERS) { 
     case 1: 
   // Link to Products 
   if ($prod_id>0) { 
//. $mosConfig_live_site .'/index2.php?option=com_oscommerce&osMod=affiliate_show_banner&
    $link= '<a href="' . $mosConfig_live_site .'/index.php?option=com_oscommerce&osMod=product_info&ref=' . $affiliate_id . '&products_id=' . $prod_id . '&affiliate_banner_id=' . $ban_id . '" target="_blank"><img src="' . HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . $affiliate_banners['affiliate_banners_image'] . '" border="0"></a>'; 
    $link2= '<a href="' . $mosConfig_live_site .'/index.php?option=com_oscommerce&osMod=product_info&ref=' . $affiliate_id . '&products_id=' . $prod_id . '&affiliate_banner_id=' . $ban_id . '" target="_blank">' . $prod_name . '</a>'; 
   } 
   // generic_link 
   else { 
    $link= '<a href="' . $mosConfig_live_site .'/index.php?option=com_oscommerce&ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id . '" target="_blank"><img src="' . HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . $affiliate_banners['affiliate_banners_image'] . '" border="0"></a>'; 
    $link2= '<a href="' . $mosConfig_live_site .'/index.php?option=com_oscommerce&ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id . '" target="_blank">' . $prod_name . '</a>'; 
             } 
   break; 
  case 2: 
   // Link to Products 
   if ($prod_id>0) { 

    $link= '<a href="' . $mosConfig_live_site .'/index.php?option=com_oscommerce&osMod=product_info&ref=' . $affiliate_id . '&products_id=' . $prod_id . '&affiliate_banner_id=' . $ban_id . '" target="_blank"><img src="' . $mosConfig_live_site .'/index2.php?option=com_oscommerce&osMod=affiliate_show_banner&ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id . '" border="0"></a>'; 
    $link2= '<a href="' . $mosConfig_live_site .'/index.php?option=com_oscommerce&osMod=product_info&ref=' . $affiliate_id . '&products_id=' . $prod_id . '&affiliate_banner_id=' . $ban_id . '" target="_blank">' . $prod_name . '</a>'; 
   } 
   // generic_link 
   else { 
    $link= '<a href="' .  $mosConfig_live_site .'/index.php?option=com_oscommerce&ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id . '" target="_blank"><img src="' . $mosConfig_live_site .'/index2.php?option=com_oscommerce&osMod=affiliate_show_banner&ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id . '" border="0"></a>'; 
    $link2= '<a href="' .  $mosConfig_live_site .'/index.php?option=com_oscommerce&ref=' . $affiliate_id . '&affiliate_banner_id=' . $ban_id . '" target="_blank">' . $prod_name . '</a>'; 
             } 
   break;  
     } 

?>
        <table width="95%" align="center" border="0" cellpadding="4" cellspacing="0" class="infoBoxContents">
          <tr>
            <td class="infoBoxHeading" align="center"><?php echo TEXT_AFFILIATE_NAME; ?>&nbsp;<?php echo $affiliate_banners['affiliate_banners_title']; ?></td>
          </tr> 
          <tr> 
            <td class="smallText" align="center"><b>Text Version:</b> <?php echo $link2; ?></td> 
          </tr> 
          <tr> 
            <td class="smallText" align="center"><?php echo TEXT_AFFILIATE_INFO; ?></td> 
          </tr> 
          <tr> 
            <td class="smallText" align="center"> 
             <textarea cols="50" rows="3" class="boxText"><?php echo $link2; ?></textarea> 
   </td> 
          </tr>
          </table>
<?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?>
<?php
   }
}
?>
          </table>
	 </td>
      </tr>
     </table></td>
<!-- body_text_eof //-->
    <td></td>
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
<?php
  require(DIR_WS_INCLUDES . 'application_bottom.php');

  // -- webMS Modification --
  // reset the Mambo Database connection (stomped by osCommerce Connection)
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
 ?>